// 登录页面
const loginPage = "/pages/login/login"

// 页面白名单
const whiteList = [
	'/pages/login/login', '/pages/register/register', '/pages/common/webview/index'
]

// 检查地址白名单
function checkWhite(url) {
	const path = url.split('?')[0]
	return whiteList.indexOf(path) !== -1
}

// 页面跳转验证拦截器
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
	uni.addInterceptor(item, {
		invoke(to) {
			if (!checkWhite((to.url))) { // 不在白名单
				console.log("不在白名单");
				const token = uni.getStorageSync('user')
				if (token === "" || token === null) {
					uni.reLaunch({
						url: "/pages/login/login"
					})
					return false
				}
			}
			return true
		},
		fail(err) {
			console.log(err)
		}
	})
})